package days25.title383;

/**
 * @Author fengzihao
 * @Date 2024-05-09 21:00
 */
class Solution {
    public boolean canConstruct(String ransomNote, String magazine) {
        if (ransomNote.length()>magazine.length())
            return false;
        for (int i = 0; i < ransomNote.length(); i++) {
            char c = ransomNote.charAt(i);
            int index = -1;
            if ((index=magazine.indexOf(c))!=-1)
                magazine = newString(magazine,index);
            else
                return false;
        }
        return true;
    }
    public String newString(String str,int index){
        return str.substring(0,index)+str.substring(index+1);
    }
}